package hr.dario.kosh;

import hr.dario.kosh.database.DataBaseAdapter;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;

public class ZujanjeActivityTwo extends ListActivity {

	private DataBaseAdapter mDbHelper;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.locations_list);
		mDbHelper = new DataBaseAdapter(this);

		
		fillData();
		registerForContextMenu(getListView());
	}

	private void fillData() {
		// Get all of the rows from the database and create the item list
		mDbHelper.open();
		Cursor EventsCursor = mDbHelper
				.fetchAllInputs(DataBaseAdapter.DATABASE_TABLE_EVENT);
		startManagingCursor(EventsCursor);

		// Create an array to specify the fields we want to display in the list
		// (only TITLE)
		String[] from = new String[] { DataBaseAdapter.KEY_EVENT_NAME,
				DataBaseAdapter.KEY_EVENT_DESCRIPTION };

		// and an array of the fields we want to bind those fields to (in this
		// case just text1)
		int[] to = new int[] { R.id.text1, R.id.text2 };

		// Now create a simple cursor adapter and set it to display
		SimpleCursorAdapter locations = new SimpleCursorAdapter(this,
				R.layout.location_row, EventsCursor, from, to);
		setListAdapter(locations);
		mDbHelper.close();
	}

	/*
	 * 
	 * private LocationService LocationService; private boolean locationBound;
	 * 
	 * @Override public void onCreate(Bundle savedInstanceState) {
	 * 
	 * super.onCreate(savedInstanceState); Cursor mCursor = getData();
	 * startManagingCursor(mCursor);
	 * 
	 * ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.list_item,
	 * mCursor, new String[] { ContactsContract.Contacts._ID,
	 * ContactsContract.Contacts.DISPLAY_NAME }, new int[] { android.R.id.text1,
	 * android.R.id.text2 }); setListAdapter(adapter);
	 * 
	 * 
	 * ListView lv = getListView();
	 * 
	 * lv.setOnItemClickListener(new OnItemClickListener() { public void
	 * onItemClick(AdapterView<?> parent, View view, int position, long id) { //
	 * When clicked, show a toast with the TextView text
	 * Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
	 * Toast.LENGTH_SHORT).show(); } });
	 * 
	 * startServices(); }
	 */
	/*
	 * private Cursor getData() { // Run query Uri uri =
	 * ContactsContract.Contacts.CONTENT_URI; String[] projection = new String[]
	 * { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME
	 * }; String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
	 * + ("1") + "'"; String[] selectionArgs = null; String sortOrder =
	 * ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
	 * 
	 * return managedQuery(uri, projection, selection, selectionArgs,
	 * sortOrder); }
	 */
	/*
	 * private void startServices() {
	 * 
	 * 
	 * // Bind to MensaLocationService Intent locationIntent = new Intent(this,
	 * LocationService.class); startService(locationIntent);
	 * bindService(locationIntent, locationConnection,
	 * Context.BIND_AUTO_CREATE);
	 * 
	 * }
	 * 
	 * private ServiceConnection locationConnection = new ServiceConnection() {
	 * 
	 * public void onServiceConnected(ComponentName componentName, IBinder
	 * iBinder) { // we've bound to local service, cast the Ibinder and get //
	 * localSErvice instance LocationService.LocalBinder binder =
	 * (LocationService.LocalBinder) iBinder; LocationService =
	 * binder.getLocationService(); locationBound = true; }
	 * 
	 * public void onServiceDisconnected(ComponentName componentName) {
	 * 
	 * locationBound = false;
	 * 
	 * } };
	 */
}